package D4;

import java.util.Scanner;

public class IdenException {
    public static void main(String[] args) {
        //自定义异常
        while (true) {
            try {
                System.out.println("请输入您的年龄：");
                Scanner sc = new Scanner(System.in);
                int age = sc.nextInt();
                saveAge(age);
                System.out.println("底层执行成功");
                break;
            } catch (java.lang.Exception e) {
                System.out.println("底层是出现bug的，请重新输入您的年龄");
                //e.printStackTrace();

            }
        }

    }
    public static void saveAge(int age){
        if (age > 0 && age <150){
            System.out.println("年龄被成功保存："+age);
        }else {
            //用一个异常对象来封装这个问题
            //throw跑出去这个异常
            throw new AgeIlegalException("/age is illegal, your age is " + age);
        }
    }
}
